package it.polimi.travelDream.ejb.servlet;

import it.polimi.travelDream.ejb.interfaces.CartMgrRemote;
import it.polimi.travelDream.ejb.interfaces.PackageMgrRemote;
import it.polimi.travelDream.ejb.interfaces.PersonalizedMgrRemote;
import it.polimi.travelDream.ejb.interfaces.HotelMgrRemote;
import it.polimi.travelDream.ejb.interfaces.ExcursionMgrRemote;
import it.polimi.travelDream.ejb.interfaces.TravelListMgrRemote;
import it.polimi.travelDream.entities.*;
import it.polimi.travelDream.entities.Package;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.lang.Object;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class TravelServlet
 */
@WebServlet("/AddPPackageToCart")
public class AddPPackageToCart extends HttpServlet {
	private static final long serialVersionUID = 1L;
 

	@EJB
	PackageMgrRemote pmgr;
	
	@EJB
	PersonalizedMgrRemote ppmgr;
	
	@EJB
	HotelMgrRemote hmgr;
	
	@EJB
	CartMgrRemote cmgr;
	
	@EJB
	TravelListMgrRemote tlmgr;
	
	public AddPPackageToCart() {
		super();
	}


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {	
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Map<String, String[]> mappa = request.getParameterMap();
		
		Modified_Package pp = ppmgr.getPersonalizedPackage(Integer.parseInt(mappa.get("idPersonalizedPackage")[0]));
		Cart cart = new Cart(1, Integer.parseInt(mappa.get("idUser")[0]), pp);
		cmgr.addToCart(cart);
		
		tlmgr.delTravelList(Integer.parseInt(mappa.get("idTravelList")[0]));
		
		request.getRequestDispatcher("/UHome.jsp").forward(request, response); 
		//response.getOutputStream().println("<h1>TravelDream</h1><h2>" + mappa.get("name")[0]+ " succesfully registered!</h2>" + "| <a href=\"Index.jsp\"> Login </a> | Registration |");
		
	}

}
